const qingtianSkybox = new mars3d.GroundSkyBox({
    sources: {
        positiveX: "/images/skybox_near/qingtian/rightav9.jpg",
        negativeX: "/images/skybox_near/qingtian/leftav9.jpg",
        positiveY: "/images/skybox_near/qingtian/frontav9.jpg",
        negativeY: "/images/skybox_near/qingtian/backav9.jpg",
        positiveZ: "/images/skybox_near/qingtian/topav9.jpg",
        negativeZ: "/images/skybox_near/qingtian/bottomav9.jpg"
    }
})

const wanxiaSkybox = new mars3d.GroundSkyBox({
    sources: {
        positiveX: "/images/skybox_near/wanxia/SunSetRight.png",
        negativeX: "/images/skybox_near/wanxia/SunSetLeft.png",
        positiveY: "/images/skybox_near/wanxia/SunSetFront.png",
        negativeY: "/images/skybox_near/wanxia/SunSetBack.png",
        positiveZ: "/images/skybox_near/wanxia/SunSetUp.png",
        negativeZ: "/images/skybox_near/wanxia/SunSetDown.png"
    }
})

const lantianSkybox = new mars3d.GroundSkyBox({
    sources: {
        positiveX: "/images/skybox_near/lantian/Right.jpg",
        negativeX: "/images/skybox_near/lantian/Left.jpg",
        positiveY: "/images/skybox_near/lantian/Front.jpg",
        negativeY: "/images/skybox_near/lantian/Back.jpg",
        positiveZ: "/images/skybox_near/lantian/Up.jpg",
        negativeZ: "/images/skybox_near/lantian/Down.jpg"
    }
})



export const BQGIS_skyBox = {
     // 默认提供的一些 mars3d.GroundSkyBox 实例
    defaultOption: {
        qingtianSkybox, // 晴天
        wanxiaSkybox, // 晚霞
        lantianSkybox, // 蓝天
    },
    /**
     *  设置天空盒
     * 
     * @param skyBox  mars3d.GroundSkyBox 实例 或者 Cesium.SkyBox 实例， 不传或为空时恢复默认天空盒
     * @param viewer: Mars3d实例对象
     * 
     */
    setSkyBox(skyBox, viewer = window.viewer) {
        if(!viewer.bq_defaultSkyBox){
            viewer.bq_defaultSkyBox = viewer.scene.skyBox;
        }
        if (viewer.bq_SkyBoxHeightEvents) {
            viewer.bq_SkyBoxHeightEvents()
        }
        if (skyBox) {
            viewer.bq_SkyBoxHeightEvents = viewer.scene.preUpdate.addEventListener(() => {
                let position = viewer.scene.camera.position;
                let cameraHeight = Cesium.Cartographic.fromCartesian(position).height;
                if (cameraHeight < 230000) {
                    viewer.scene.skyBox = skyBox;
                    viewer.scene.skyAtmosphere.show = false;
                } else {
                    viewer.scene.skyBox = viewer.bq_defaultSkyBox;
                    viewer.scene.skyAtmosphere.show = true;
                }
            })
        }else {
            viewer.scene.skyBox = viewer.bq_defaultSkyBox;
            viewer.scene.skyAtmosphere.show = true;
        }
    }
}